//===============================================================
// File		:	CModelManager.h
//
// Purpose	:	Used to load an x-File to create a model and assign a unique ID to that model. The model
//					manager keeps track of all models loaded into the game. 
//
// Author	: 	Michael Pedro
//
// Date		: 	5/10/2009
//===============================================================
#pragma once
#include "d3d9.h"
#include "d3dx9.h"
#include <vector>
#include <map>

// safely release com objects.
#define SAFE_RELEASE(p)	if (p) { p->Release(); p = NULL; }

struct tModel
{
	ID3DXMesh*									mesh;
	std::vector<D3DMATERIAL9>			mtrls;
	std::vector<IDirect3DTexture9*>		textures;
	D3DXMATRIX									matTransform;
	const char*									fileName;
};

class CModelManager
{
	typedef std::map<int, tModel> ModelMap;
	ModelMap m_Models;                          // Map containing all models.
	LPDIRECT3DDEVICE9 m_pDevice;                // Our D3D device

protected:
	CModelManager();
	CModelManager(const CModelManager&) {}
	CModelManager& operator=(const CModelManager&) {}	
	~CModelManager();
public:

	//=====================================================
	// Function	:	GetInstance()
	//
	// Out		:	CModelManager& - Handle to our single modelmanager class instance
	//
	//	Purpose	:	To return a reference to our model manager Class Instance
	//=====================================================
	static CModelManager* GetInstance(void);
	
    //=====================================================
	// Function	:	Initialize()
	//
	// In		:	device - our d3d device
	//
	// Out      :   true if we initalize successfully
	//
	//	Purpose	:	store a local copy of our d3d device pointer
	//=====================================================
	bool Initialize(IDirect3DDevice9* device);

	//=====================================================
	// Function	:	AddModel()
	//
	// In			:	szFileName - The name of the model to load
	//
	// Out		:	int - Handle to our newly added model
	//
	//	Purpose	:	Create a new model and assign a unique ID to that model.
	//=====================================================
	int AddModel(const char* szFileName);

	//=====================================================
	// Function	:	DrawAllModels()
	//
	//	Purpose	:	Render all of the models in our collection of models.
	//=====================================================
	void DrawAllModels(void);

	//=====================================================
	// Function	:	DrawModel()
	//
	//	In			:	nID - The ID of the model to render.
	//
	//	Purpose	:	Render a specific model in our model List.
	//=====================================================
	bool DrawModel(int nID);

	//=====================================================
	// Function	:	CleanUp()
	//
	//	Purpose	:	Clean up where needed. Release any allocated memory
	//=====================================================
	void CleanUp(void);

	void ScaleModel(int nID, float x, float y, float z);
	void TranslateModel(int nID, float x, float y, float z);
};
